package com.springcloud.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 服务消费者可以返回JSON或视图页面
 * 我们使用@RestController仅仅是方便测试
 */
@RestController
public class ConsumerController {

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("/test")
    public Object test(){
        String url="http://localhost:8081/test";
        ResponseEntity<String> responseEntity= restTemplate.getForEntity(url,String.class);
        System.out.println(responseEntity.getStatusCode());
        System.out.println(responseEntity.getStatusCodeValue());
        System.out.println(responseEntity.getHeaders());
        String body=responseEntity.getBody();
        return "第一个SpringCloud服务消费者-----"+body;
    }
}
